home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: stricmp()
- Date: Fri, 12 Jan 96 00:32:34 GMT
- Organization: none
- Message-ID: <821406754snz@genesis.demon.co.uk>
- References: <TANMOY.96Jan10212912@qcd.lanl.gov> <8213825629501@demosys.gcomm.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <8213825629501@demosys.gcomm.com>
- jackal@gcomm.com "Jack Alvrus" writes:
-
- >
- >TA>A rare post with so many wrong assumptions!!! :-)
- >
- >Well, if they're wrong it's a good thing I made this post to find out,
- >eh? :)
- >
- >TA> stricmp() is an ANSI library function, right? So it should exhibit, if
- >
- >TA>no.
- >
- >So far that's been the overwhelming response, and if that is in fact
- >correct that's fine.
-
- It is correct. ISO 9899-1990 (which is the standard re-adopted by ANSI) does
- not define a stricmp function.
-
- > I do not have access to a copy of the ANSI C spec
- >so I cannot verify this for myself, however, the Borland C++ v4.5
- >Library Reference manual states that stricmp() is "defined by the ANSI C
- >standard." Perhaps someone should notify Borland?
-
- Probably.
-
- >TA> not consistent, at least *documented* behavior, right?
- >
- >TA>no and no. Usually library functions have certain requirments on their
- >TA>parameters, and a violation of these can lead to undefined behaviour,
- >TA>which need neither be consistent nor documented.
- >
- >Ah, but the requirements ARE documented. If, under certain conditions,
- >behavior is undefined, then if those conditions are documented the
- >behavior is also documented. These conditions are part of what I'm
- >trying to find out.
-
- Any implementation can define behaviour for code that the C standard leaves
- undefined. Such code has defined behaviour but only under that particular
- implementation - i.e. it is not portable. The C language doesn't define
- any behaviour for stricmp() so you're entirely in the hands of the
- implementation. However consider:
-
- strcmp("^", "a")
-
- or even just
-
- '^' > 'a'
-
- strcmp is a standard C library function but even with this here you cannot
- tell from the C standard alone what the result of this will be (I guess
- you can determine that the characters/strings compare unequal). The C
- standard leaves the collating sequence of the character set implementation
- defined (except when the digits '0' to '9' are compared with each other).
- This means that the expressions above have values with will be consistent
- with other comparisons in the character set but you cannot tell in isolation
- what the result will be without reference to the implementation documentation.
- If you change to a different implementation you may get completely different
- results but they will be consistent within that implementation.
-
- You could implement a function that takes 2 strings, transforms every
- character in both strings using the ANSI defined toupper() function and then
- compares the 2 resulting strings. This would be a reasonable definition of a
- stricmp function using only ANSI functions and operations (or you could
- use tolower all through instead of toupper). In that case you still can't
- determine purely from the C language standard whether "^" or "a" will
- compare greater. A conforming implementation must provide adequate
- documentation to determine this however. Of course this doesn't help define
- the stricmp function your implementation happens to provide at all.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-